<template>
  <div id="app">
      <el-container>
          <el-header></el-header>
          <el-main>
              <el-descriptions class="margin-top" title="订单" :column="3" :size="size" :model="orderForm">
  <template slot="extra">
    <el-button type="primary" size="small" @click="comfire">确认订单</el-button>
  </template>
  <el-descriptions-item label="桌号" v-model="orderForm.deskId">{{orderForm.deskId}}</el-descriptions-item>
  <el-descriptions-item label="用餐人数" v-model="orderForm.peopleNumber">{{orderForm.peopleNumber}}</el-descriptions-item>
  <el-descriptions-item label="总金额" v-model="orderForm.totalAmount">{{orderForm.totalAmount}}</el-descriptions-item>
  <el-descriptions-item label="取单号" v-model="orderForm.fetchNumber">{{orderForm.fetchNumber}}</el-descriptions-item>
</el-descriptions>
<el-row>
      <el-button type="primary" @click="info">查看详情</el-button>
  </el-row>
          </el-main>
          <el-footer></el-footer>
      </el-container>
  </div>
</template>
<script>
  export default {
  data () {
    return {
      size: '',
      orderForm:{
          orderNumber:'',
          deskId:'',
          peopleNumber:'',
          totalAmount:'',
          fetchNumber:'',
          
      },
      modifyForm:{
          orderNumber: '',
          orderStatus:'END_ORDER'
      }
    };
  },
  methods:{
      query(){
          this.$axios.get("http://localhost:8082/getOrderToUser",
              {
                 params:{
                  orderNumber: 11
                  
              } 
              }).then(resp=>{
          
          let result = resp.data;
          if(result.code=='200'){
              this.orderForm=result.data;
              this.modifyForm.orderNumber=this.orderForm.orderNumber
              
          }
      })
      .catch(error=>{console.error(error)})
              
          
      },
      info(){    
             
          this.$router.push({
          name:'orderinfo',
          query:{
          random:Math.random(),
          orderNumber:11,
          }
          })
      },
      comfire(){
          console.log(this.modifyForm)
          this.$axios.put("http://localhost:8082/modifyOrder",this.modifyForm)
          .then(response=>{//业务异常
                      if(response.data.code!='200'){
                          this.$message.error("添加失败："+response.data.message);
                      }else{
                          this.$message.success("确认订单")
                      }
                  })
                  .catch(error=>{ //通信异常
                      console.error(error);
                  })
      }
  },
  mounted(){
      this.query();
  }
}
</script>
